import { Component, OnInit } from '@angular/core';
import { User } from './classes/user';
import { BatchActionsService } from './core/share/modal-box/batch-actions.service';
import { UserService } from './services/user/user.service';
import { ModalBoxType } from './core/share/modal-box/modal-box.reducer';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})
export class AppComponent implements OnInit {

  user: User;

  constructor(
    private batchActionService: BatchActionsService,
    private userService: UserService
  ) { }

  ngOnInit() {
    // 检查用户登录
    this.userService.getUser().subscribe(user => this.user = user);
  }

  openModalBox(modalBoxType?: ModalBoxType) {
    this.batchActionService.controlModalBox(true, modalBoxType);
  }

  changeModalBox(type: ModalBoxType.Default) {
    this.batchActionService.changeModalBox(type);
  }

  logout() {
    this.userService.logout();
  }
}

